<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:c="http://java.sun.com/jstl/core"
	xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core"
	xmlns:rich="http://richfaces.ajax4jsf.org/rich"
	xmlns:a4j="https://ajax4jsf.dev.java.net/ajax"
	xmlns:t="https://code.google.com/p/rad-framework/taglib"
	xmlns:tt="https://code.google.com/p/rad-framework"
	xmlns:s="http://jboss.com/products/seam/taglib" template="#{theme.entity}">
	
	<ui:define name="edit-view-action">
		<tt:link id="viewLink"
			path="#{tree.master.viewPath}"
			entityName="#{currentTree.type}"
			key="#{currentTree.key}"
			mode="View"
			rendered="#{currentTree.editor.renderView}"
			styleClass="rad-framework-action-panel">
			<h:outputText styleClass="rad-framework-action-view" value="#{messages['View']}" />
			<s:conversationId/>
		</tt:link>
	</ui:define>
	
	<ui:define name="main">
		<a4j:form id="editForm" enctype="#{currentTree.multipart ? 'multipart/form-data' : null}">
			<h:panelGrid columns="1" cellspacing="4">
				<h:panelGroup>
					<a4j:commandLink id="saveButton" type="submit"
						eventsQueue="viewQ"
						reRender="crumbs,view,recent,workflowActionsPanel,sidebarForm"
						rendered="#{!currentTree.editor.endConversation and !currentTree.multipart}"
						action="#{currentTree.save}"
						styleClass="rad-framework-button-content">
						<s:conversationId/>
						<span><h:outputText value="#{messages['Save']}" /></span>
					</a4j:commandLink>
					<h:commandLink id="saveMultipartButton" type="submit"
						rendered="#{currentTree.editor.endConversation or currentTree.multipart}"
						action="#{currentTree.save}"
						styleClass="rad-framework-button-content">
						<s:conversationId/>
						<span><h:outputText value="#{messages['Save']}" /></span>
					</h:commandLink>
					<s:link id="cancelButton" type="submit"
						view="#{currentTree.parentViewId}"
						value="#{messages['Cancel']}"
						rendered="#{!currentTree.editor.managed}">
						<f:param name="id" value="#{currentTree.parentEntityNode.key}" />
					</s:link>
				</h:panelGroup>
			</h:panelGrid>
			
			<tt:validate-panel>
				<ui:include
					src="/#{viewPath == null ? 'jsf' : viewPath}/#{currentTree.viewPath}#{currentTree.type}/EditPanel.xhtml">
					<ui:param name="entity" value="#{currentTree.instance}"/>
					<ui:param name="label" value="#{messages['General']}"/>
				</ui:include>
			</tt:validate-panel>
		</a4j:form>
		
	</ui:define>
	
	<ui:define name="folders">
		<s:fragment rendered="#{currentTree.editor.managed}">
		<c:forEach items="#{currentTree.childList}" var="folder">
			<rich:spacer rendered="#{folder.rendered}" width="1" height="5"/>
			<tt:toggle-panel
				id="#{folder.id}TP"
				label="#{folder.text} (#{folder.childCount})"
				rendered="#{folder.rendered}"
				switchType="#{folder.ajaxMode}"
				actionListener="#{folder.expandListener}"
				opened="#{folder.opened}">
				
				<ui:remove>
				<a4j:support event="onclick" actionListener="#{folder.expandListener}" eventsQueue="viewQ" />
				<a4j:support event="oncollapse" actionListener="#{folder.collapseListener}" eventsQueue="viewQ" />
				</ui:remove>
				
				<ui:include src="#{folder.editPanel}">
					<ui:param name="id" value="#{folder.id}"/>
				</ui:include>
				
			</tt:toggle-panel>
		</c:forEach>
		</s:fragment>
	</ui:define>
</ui:composition>